﻿using DG.Tweening;
using System.Collections;
using UnityEngine;


public class Weapon : MonoBehaviour, IInteractable
{
    public string weaponName;
    public void init(string weaponName,Sprite weaponSprite)
    {
        this.weaponName = weaponName;
        GetComponent<SpriteRenderer>().sprite = weaponSprite;
    }
    public void ChangeBeforeInteracte()
    {
    }
    public void Interacte(GameObject trigger)
    {
        trigger.GetComponent<PlayerWeaponController>()?.EquipWeapon(weaponName);
        Destroy(gameObject);
    }
    public void ChangeAfterInteracte()
    {
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            collision.gameObject.GetComponent<PlayerController>().AddInteractObject(this);
        }
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            collision.gameObject.GetComponent<PlayerController>().RemoveInteractObject(this);
        }
    }
}
